package com.woniuxy.moneyapp.config;

import cn.hutool.core.date.DateTime;
import com.baomidou.mybatisplus.core.handlers.MetaObjectHandler;
import org.apache.ibatis.reflection.MetaObject;
import org.springframework.stereotype.Component;

import java.time.LocalDateTime;


@Component
public class AutoFillHandler implements MetaObjectHandler {

    /**
     * 新增时如何处理
     * @param metaObject
     */
    @Override
    public void insertFill(MetaObject metaObject) {
        LocalDateTime time = LocalDateTime.now();
        System.out.println("自动添加:"+time+"+++++++++++++++++++++++++++++++++++");
        this.setFieldValByName("createTime",time,metaObject);
    }

    /**
     * 修改时如何处理
     * @param metaObject
     */
    @Override
    public void updateFill(MetaObject metaObject) {
        LocalDateTime time = LocalDateTime.now();
        System.out.println("自动更新:"+time+"+++++++++++++++++++++++++++++++++++");
        this.setFieldValByName("responseTime",time,metaObject);
    }
}
